<template>
	<view class="login">
		<!-- 用户头像 -->
		<image class="avtar" src="http://8.130.66.190/img/Felinus.jpg" />
		<view class="username">
			<input class="input" type="text" placeholder="请你输入用户昵称" v-model="data.nickname" />
		</view>
		<view class="footer" @click="confirmLogin">
			<button class="footer-button" type="primary">确认登录</button>
		</view>
	</view>
</template>

<script>
	import {
		reqConfirmLogin,
		reqGetUserInfo
	} from '../../api/index.js'
	export default {
		data() {
			return {
				data: {
					nickname: '', //用户昵称
					headimgurl: '', //用户头像
				}
			}
		},
		mounted() {
			this.getUserInfo()
		},
		methods: {
			// 获取用户信息
			async getUserInfo() {
				const result = await reqGetUserInfo();
				if (result.code === 200) {
					this.data.nickname = result.data.nickname,
						this.data.headimgurl = result.data.headimgurl
				}
			},
			// 确认登录
			async confirmLogin() {
				await reqConfirmLogin(this.data);
				uni.reLaunch({
					url: '/pages/my/index',
				})
				uni.showToast({
					title: '登录成功',
					icon: 'success'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.login {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 30rpx;

		.avtar {
			width: 300rpx;
			height: 300rpx;
			border-radius: 50%;
		}

		.username {
			display: flex;
			justify-content: center;

			.input {
				text-align: center;
				margin: 60rpx 0;
				font-size: 36rpx;
			}
		}
		.footer{
			.footer-button{
				width: 600rpx;
				border-radius: 60rpx;
			}
		}
	}
</style>